package hcs.settings;

import hcs.interfaces.IHouseSettings;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XMLSettings implements IHouseSettings {

	private double standardAwayTemp;
	private double standardPresenceTemp;
	private int standardAwayTime;
	private int standardHeatingTime;
	private int standardInsideTime;
	private String[] roomNames;
	private int[] sqm;
	
	public XMLSettings(Document xmlDoc) {
		Element hcsE = xmlDoc.getDocumentElement();
		Node temp = hcsE.getElementsByTagName("standard-temperatures").item(0);
		NamedNodeMap tempattr =  temp.getAttributes();
		standardAwayTemp = Double.valueOf(tempattr.getNamedItem("away").getNodeValue());
		standardPresenceTemp = Double.valueOf(tempattr.getNamedItem("presence").getNodeValue());
		Node times = hcsE.getElementsByTagName("standard-times").item(0);
		NamedNodeMap timeattr = times.getAttributes();
		standardAwayTime = Integer.valueOf(timeattr.getNamedItem("away").getNodeValue());
		standardInsideTime = Integer.valueOf(timeattr.getNamedItem("inside").getNodeValue());
		standardHeatingTime = Integer.valueOf(timeattr.getNamedItem("heating").getNodeValue());
		NodeList roomNodes =  hcsE.getElementsByTagName("room");
		roomNames = new String[roomNodes.getLength()];
		sqm = new int[roomNodes.getLength()];
		for(int i = 0; i < roomNodes.getLength(); i++) {
			Node j =  roomNodes.item(i);
			NamedNodeMap roomMap = j.getAttributes();
			roomNames[i] = roomMap.getNamedItem("name").getNodeValue();
			sqm[i] = Integer.valueOf(roomMap.getNamedItem("sqm").getNodeValue());
		}
	}
	
	public double StandardAwayTemp() {
		return standardAwayTemp;
	}

	public int StandardAwayTime() {
		return standardAwayTime;
	}

	public int StandardHeatingTime() {
		return standardHeatingTime;
	}

	public int StandardInsideTime() {
		return standardInsideTime;
	}

	public double StandardPresenceTemp() {
		return standardPresenceTemp;
	}

	public String[] getRoomNames() {
		return roomNames;
	}

	public int[] getSqm() {
		return sqm;
	}

}
